package com.game.tiledmap;

import com.game.character.Character;
import com.game.framwork.gamesupport.GameSprite;
import com.game.framwork.itf.Graphics;
import com.game.framwork.itf.Pixmap;
import com.game.object.JObject;

public class Tiled extends Character {
	public int typeTiled;
	private Pixmap pImage;
	private TiledDestroyEffect tiledDestroyEffect;

	public Tiled(int pos, int type, Pixmap pImage) {
		this.posOnMap = pos;
		this.pImage = pImage;
		this.isDeath = false;
		this.isVisible = true;
		frameWidth = 50;
		frameHeight = 83;
		init(type);
	}

	public void init(int typeTiled) {
		int count = 8;
		GameSprite[] pAnim;
		pAnim = new GameSprite[2];
		pAnim[0] = new GameSprite(pImage);
		pAnim[0].createAnimation("Tiled", typeTiled, typeTiled, typeTiled, 1.0f);
		pAnim[1] = new GameSprite(pImage);
		pAnim[1].createAnimation("Destroy", 0, 0, 0, 1.0f);
		loadSprite(pImage, count, count, frameWidth, frameHeight, pAnim);
		changeAnimation("Tiled");
		tiledDestroyEffect = new TiledDestroyEffect();
		
		canCollision = false;
		canBeDestroy = false;
		isDestroy = false;
		this.typeTiled = typeTiled;
		if (this.typeTiled > 3) {
			canCollision = true;
		}
		if (this.typeTiled > 4) {
			canBeDestroy = true;
		}
	}

	@Override
	public void updateInternal(float deltaTime) {
		if (!isDeath) {
			if (isDestroy) {
				tiledDestroyEffect.setPossition(position);
				tiledDestroyEffect.attachTiledMap(tiledMap);
				tiledDestroyEffect.updateInternal(deltaTime);
				return;
				//changeAnimation("Destroy");
				//isDestroy = false;
			}
			//tiledDestroyEffect.getCurrAnimation().resetAnimation();
			super.updateInternal(deltaTime);
		}
	}

	@Override
	public void paintInternal(Graphics g) {
		if (!isDeath) {
			if (isDestroy) {
				tiledDestroyEffect.paintInternal(g);
				return;
			}
			super.paintInternal(g);	
		}
	}

	@Override
	public boolean Collision(JObject pObj) {
		return super.Collision(pObj);
	}
}
